 package tools;

 import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.OutputStream;
 import java.net.HttpURLConnection;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;

 public class HttpUtil
 {
   public static String doGet(String httpurl) {
/*  19 */     HttpURLConnection connection = null;
/*  20 */     InputStream is = null;
/*  21 */     BufferedReader br = null;
/*  22 */     String result = null;

     try {
/*  25 */       URL url = new URL(httpurl);

/*  27 */       connection = (HttpURLConnection)url.openConnection();

/*  29 */       connection.setRequestMethod("GET");

/*  31 */       connection.setConnectTimeout(15000);

/*  33 */       connection.setReadTimeout(60000);

/*  35 */       connection.connect();

/*  37 */       if (connection.getResponseCode() == 200) {
/*  38 */         is = connection.getInputStream();

/*  40 */         br = new BufferedReader(new InputStreamReader(is, "UTF-8"));

/*  42 */         StringBuffer sbf = new StringBuffer();
/*  43 */         String temp = null;
/*  44 */         while ((temp = br.readLine()) != null) {
/*  45 */           sbf.append(temp);
/*  46 */           sbf.append("\r\n");
         }
/*  48 */         result = sbf.toString();
       }
/*  50 */     } catch (MalformedURLException e) {
/*  51 */       e.printStackTrace();
/*  52 */     } catch (IOException e) {
/*  53 */       e.printStackTrace();
     } finally {

/*  56 */       if (null != br) {
         try {
/*  58 */           br.close();
/*  59 */         } catch (IOException e) {
/*  60 */           e.printStackTrace();
         }
       }

/*  64 */       if (null != is) {
         try {
/*  66 */           is.close();
/*  67 */         } catch (IOException e) {
/*  68 */           e.printStackTrace();
         }
       }

/*  72 */       connection.disconnect();
     }

/*  75 */     return result;
   }









   public static String doPost(String httpUrl, String param, String contentType) {
/*  87 */     HttpURLConnection connection = null;
/*  88 */     InputStream is = null;
/*  89 */     OutputStream os = null;
/*  90 */     BufferedReader br = null;
/*  91 */     String result = null;
     try {
/*  93 */       URL url = new URL(httpUrl);

/*  95 */       connection = (HttpURLConnection)url.openConnection();

/*  97 */       connection.setRequestMethod("POST");

/*  99 */       connection.setConnectTimeout(15000);

/* 101 */       connection.setReadTimeout(60000);


/* 104 */       connection.setDoOutput(true);

/* 106 */       connection.setDoInput(true);

/* 108 */       if (!contentType.isEmpty()) {
/* 109 */         connection.setRequestProperty("Content-Type", contentType);
       }





/* 116 */       os = connection.getOutputStream();

/* 118 */       if (param.length() > 0) {
/* 119 */         os.write(param.getBytes());
       }


/* 123 */       if (connection.getResponseCode() == 200) {

/* 125 */         is = connection.getInputStream();

/* 127 */         br = new BufferedReader(new InputStreamReader(is, "UTF-8"));

/* 129 */         StringBuffer sbf = new StringBuffer();
/* 130 */         String temp = null;

/* 132 */         while ((temp = br.readLine()) != null) {
/* 133 */           sbf.append(temp);
         }

/* 136 */         result = sbf.toString();
       }
/* 138 */     } catch (MalformedURLException e) {
/* 139 */       e.printStackTrace();
/* 140 */     } catch (IOException e) {
/* 141 */       e.printStackTrace();
     } finally {

/* 144 */       if (null != br) {
         try {
/* 146 */           br.close();
/* 147 */         } catch (IOException e) {
/* 148 */           e.printStackTrace();
         }
       }
/* 151 */       if (null != os) {
         try {
/* 153 */           os.close();
/* 154 */         } catch (IOException e) {
/* 155 */           e.printStackTrace();
         }
       }
/* 158 */       if (null != is) {
         try {
/* 160 */           is.close();
/* 161 */         } catch (IOException e) {
/* 162 */           e.printStackTrace();
         }
       }

/* 166 */       connection.disconnect();
     }
/* 168 */     return result;
   }







   public static String doPostForm(String httpUrl, Map<String, String> param, String contentType) {
/* 178 */     HttpURLConnection connection = null;
/* 179 */     InputStream is = null;
/* 180 */     OutputStream os = null;
/* 181 */     BufferedReader br = null;
/* 182 */     String result = null;
     try {
/* 184 */       URL url = new URL(httpUrl);

/* 186 */       connection = (HttpURLConnection)url.openConnection();

/* 188 */       connection.setRequestMethod("POST");

/* 190 */       connection.setConnectTimeout(15000);

/* 192 */       connection.setReadTimeout(60000);


/* 195 */       connection.setDoOutput(true);

/* 197 */       connection.setDoInput(true);

/* 199 */       if (!contentType.isEmpty()) {
/* 200 */         connection.setRequestProperty("Content-Type", contentType);
       }




/* 206 */       os = connection.getOutputStream();

/* 208 */       os.write(createLinkString(param).getBytes());

/* 210 */       if (connection.getResponseCode() == 200) {

/* 212 */         is = connection.getInputStream();

/* 214 */         br = new BufferedReader(new InputStreamReader(is, "UTF-8"));

/* 216 */         StringBuffer sbf = new StringBuffer();
/* 217 */         String temp = null;

/* 219 */         while ((temp = br.readLine()) != null) {
/* 220 */           sbf.append(temp);
/* 221 */           sbf.append("\r\n");
         }
/* 223 */         result = sbf.toString();
       }
/* 225 */     } catch (MalformedURLException e) {
/* 226 */       e.printStackTrace();
/* 227 */     } catch (IOException e) {
/* 228 */       e.printStackTrace();
     } finally {

/* 231 */       if (null != br) {
         try {
/* 233 */           br.close();
/* 234 */         } catch (IOException e) {
/* 235 */           e.printStackTrace();
         }
       }
/* 238 */       if (null != os) {
         try {
/* 240 */           os.close();
/* 241 */         } catch (IOException e) {
/* 242 */           e.printStackTrace();
         }
       }
/* 245 */       if (null != is) {
         try {
/* 247 */           is.close();
/* 248 */         } catch (IOException e) {
/* 249 */           e.printStackTrace();
         }
       }

/* 253 */       connection.disconnect();
     }
/* 255 */     return result;
   }








   public static String createLinkString(Map<String, String> params) {
/* 266 */     List<String> keys = new ArrayList<>(params.keySet());
/* 267 */     Collections.sort(keys);

/* 269 */     StringBuilder prestr = new StringBuilder();
/* 270 */     for (int i = 0; i < keys.size(); i++) {
/* 271 */       String key = keys.get(i);
/* 272 */       String value = params.get(key);
/* 273 */       if (i == keys.size() - 1) {
/* 274 */         prestr.append(key).append("=").append(value);
       } else {
/* 276 */         prestr.append(key).append("=").append(value).append("&");
       }
     }

/* 280 */     return prestr.toString();
   }
 }


/* Location:              C:\PGX\Server.jar!\tools\HttpUtil.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */